<?php
 /***************************************************************
 * Mor-MVC Framework, A framework that can easily let you build a powerful
 * and scalable web application based on PHP language,
 * this framewrok is a copy of the Zend Behavior Framework
 *  Copyright (C) 2010  Nabil Droussi <nabildroussi@gmail.com>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ***************************************************************/
require_once("DBI.class.php");

class DBAdapter
{
	private static $_instance = NULL;
	private $_host = "";
	private $_dbname = "";
	private $_user = "";
	private $_pass = "";
	private $_dbInterface;
	private function __construct()
	{
		$dbUrl = "mysql://{$this->_user}:{$this->_pass}@{$this->_host}/{$this->_dbname}";
		$this->_dbInterface = new DBI($dbUrl);
		if($this->_dbInterface->isError())
			throw new Exception("Cannot connect to the database server. \nDetail : ".$this->_dbInterface->getError());
	}
	public static function getInstance()
	{
		if(is_null(self::$_instance) == TRUE)
		{
			self::$_instance = new DBAdapter();
		}
		return self::$_instance;
	}
	public function getDBInterface()
	{
		return $this->_dbInterface;
	}
	function __destruct()
	{
		if($this->_dbInterface->isConnected())
			$this->_dbInterface->disconnect();
	}
}